/*
 * Copyright (C) 2010-2010 MaoJian Wu
 *
 * Author:
 *	MaoJian Wu
 *
 * Source:
 *	
 *
 * This file is a part of zfspear library.
 *
 *
 */

#ifndef XMPP_STREAM_PARSER_H
#define XMPP_STREAM_PARSER_H

#include <QObject>
#include <QXmlStreamReader>

#include <xmpp_element_factory.h>
class XmppElement;

class XmppStreamParser : public QObject {
    Q_OBJECT
public:
    explicit XmppStreamParser(QObject *parent = 0);
    void Parser(const QByteArray& data);
signals:
    void OnStreamStart(XmppElement* xmppElement);
    void OnStreamEnd(XmppElement* xmppElement);
    void OnStreamElement(XmppElement* xmppElement);
    void OnXmlError(const QString& xml);
public slots:
private:
    QXmlStreamReader xml_stream_reader_;
    void DoElementParser();
    bool HasStartStreamElement(const QByteArray& data);
    bool HasEndStreamElement(const QByteArray& data);
    XmppElement *current_;
    XmppElement *root_;
    XmppElementFactory xmppElementFactory_;
    static const QByteArray kStreamRootElementStart;
    static const QByteArray kStreamRootElementEnd;
};

#endif // XMPP_STREAM_PARSER_H
